<?php
namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Model\OperationLogs;
use App\Model\Nameplate;

class NameplateController extends BaseController
{
    protected $model = null;

    public function __construct(Request $request)
    {
        parent::__construct($request);
        $this->model = new Nameplate();
    }

    //铭牌新增
    public function nameplateAdd(Request $request){
        $res = $this->model->nameplateAdd($request->all(), $this->user);
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '铭牌新增');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //铭牌编辑
    public function nameplateEdit(Request $request){
        $res = $this->model->nameplateEdit($request->all(), $this->user);
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '铭牌编辑');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //铭牌用户下发记录新增
    public function nameplateUserAdd(Request $request){
        $res = $this->model->nameplateUserAdd($request->all(), $this->user);
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '铭牌用户下发记录新增');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //铭牌用户下发记录编辑
    public function nameplateUserEdit(Request $request){
        $res = $this->model->nameplateUserEdit($request->all(), $this->user);
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '铭牌用户下发记录编辑');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //铭牌用户下发记录删除
    public function nameplateUserDel(Request $request){
        $res = $this->model->nameplateUserDel($request->all(), $this->user);
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '铭牌用户下发记录删除');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //铭牌列表
    public function nameplateList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->nameplateList($request));
    }

    //铭牌下发列表
    public function nameplateUserList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->nameplateUserList($request));
    }

}
